// pages/my/replaceProduct/addExistOldGood.js
const app = getApp()
Page({
  data: {
    good:[],
    goodsInfoShow:true,
    count:1,
    agentId:'',
    accountId:''
  },
  onLoad: function (options) {
    app.getMemInfo().then(res=>{
      this.setData({
        agentId:res.data.agentId,
        accountId:res.data.id
      })
    })
    let goodInfo = JSON.parse(options.good)
    console.log(goodInfo)
    let good = []
    good.push({
      name:goodInfo.product_name,
      url:goodInfo.main_img_url,
      type:goodInfo.version_values,
      img_url1:goodInfo.img_url1,
      img_url2:goodInfo.img_url2,
      img_url3:goodInfo.img_url3,
      img_url4:goodInfo.img_url4,
      price:0,
      id:goodInfo.id,
      companyName:goodInfo.productTag,
      color:goodInfo.tagColor
    })
    this.setData({
      good
    })
  },
  onShow: function () {

  },
  sub(){
    let count = this.data.count
    if (count>1) {
      count--
    }
    this.setData({
      count
    })
  },
  add(){
    let count = this.data.count
    count++
    this.setData({
      count
    })
  },
  getPrice(e){
    this.setData({
      ['good[0].price']:e.detail.value
    })
  },

  addOldGoodInfo(){
    let data = {
      id:this.data.good[0].id,
      price:this.data.good[0].price,
      amount:this.data.count
    }
    console.log(data)
    app.request('wx_app/oldForNew/oldSkuListHistory/add',data,'GET').then(res=>{
      console.log(res)
      if (res.code==1) {  
        let pages = getCurrentPages();//当前页面
        let prevPage = pages[pages.length-3];
        let oldIds = prevPage.data.oldIds
        oldIds.push(res.data)
        prevPage.setData({
          oldIds
        });
        app.errorMsg('上传成功')
        wx.navigateBack({
          delta:2
        })
      }else{
        app.errorMsg(res.message)
      }
    })

  },
})